﻿using System;
using System.Data;
using NVelocity;

namespace Syno.Core.Output.DataDisplay
{
    public class TextTableDisplay : IDataDisplay
    {
        protected readonly TemplateDisplay _templateDisplay;



        public TextTableDisplay()
        {
            _templateDisplay = new TemplateDisplay();
            Heading = "No Heading specified";
            _templateDisplay.Template = @"$heading
-------------------------
#foreach($column in $data.Columns)
#beforeall
#each
$column     #after
#nodata
Strange there are no columns
#end

#foreach($row in $data.Rows)
#each
#foreach($column in $data.Columns)
#each
$row.get_Item($column)      #after
    #nodata
    Strange there are no columns
    #end
#after

#nodata
no records found
#end";
        }


        public virtual string Display(DataTable data)
        {
            _templateDisplay.AddContext("heading",Heading);
            return _templateDisplay.Display(data);
        }

        public string Heading { get; set; }
    }
}